﻿using System.Collections.Generic;
using ML.Entity;
using ML.IRepository;
using Dapper;

namespace ML.Repository
{
    /// <summary>
    /// 订单详情仓储实现类
    /// </summary>
    public class OrderDetailsRepository : DBFactory, IOrderDetailsRepository
    {
        public IEnumerable<OrderDetailResponse> GetDetailById(string id)
        {
            const string sql = @"SELECT p.Name,od.* FROM ml_orderdetails od
	            INNER JOIN ml_product p on od.ProductId=p.Id WHERE od.OrderId=@OrderId";
            using (_db)
            {
                return _db.Query<OrderDetailResponse>(sql, new { OrderId = id });
            }
        }

        public OrderDetailsEntity GetById(string id)
        {
            throw new System.NotImplementedException();
        }

        public IEnumerable<OrderDetailResponse> GetOrderDetailIds(List<string> orderIds)
        {
            const string sql = @"SELECT p.Name,od.* FROM ml_orderdetails od
	            INNER JOIN ml_product p on od.ProductId=p.Id WHERE od.OrderId in @OrderId";
            using (_db)
            {
                return _db.Query<OrderDetailResponse>(sql, new { OrderId = orderIds.ToArray() });
            }
        }

        public IEnumerable<OrderDetailsEntity> GetOrderDetailByProductId(string Id)
        {
            const string sql = @"SELECT * FROM ml_orderdetails WHERE ProductId=@ProductId";
            using (_db)
            {
                return _db.Query<OrderDetailsEntity>(sql, new { @ProductId = Id });
            }
        }

        public bool Add(OrderDetailsEntity entity)
        {
            throw new System.NotImplementedException();
        }

        public bool Update(OrderDetailsEntity entity)
        {
            throw new System.NotImplementedException();
        }

        public bool Delete(OrderDetailsEntity entity)
        {
            throw new System.NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new System.NotImplementedException();
        }
    }
}